package com.datam.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.datam.dao.CompanyJkDeviceDAO;
import com.datam.dao.CompanyZlDeviceDAO;
import com.datam.domain.CompanyJkDeviceDO;
import com.datam.domain.CompanyZlDeviceDO;
import com.datam.domain.ConpanyTxInfoDO;
import com.datam.query.QueryCompanyJkDevice;
import com.datam.query.QueryCompanyZlDevice;
import com.datam.query.QueryConpanyTxInfo;
import com.datam.utils.DMResult;


@Controller
public class JKController {
	
	private static Logger logger = LoggerFactory.getLogger(PKController.class);

	@Autowired
	CompanyJkDeviceDAO  companyJkDeviceDAO;
	
	@Autowired
	CompanyZlDeviceDAO companyZlDeviceDAO ;

	@RequestMapping("VOCsCompany/GetJKDeviceData")
	public @ResponseBody Object GetJKDeviceData(HttpServletRequest request, HttpServletResponse response,
			Long ID){
		try {
			QueryCompanyJkDevice queryCompanyJkDevice = new QueryCompanyJkDevice();
			queryCompanyJkDevice.setCOMPANYID(ID);
			List< CompanyJkDeviceDO > data = companyJkDeviceDAO.selectCompanyJkDeviceList(queryCompanyJkDevice);
			Map r = new HashMap();
			r.put("total", data.size());
			r.put("rows", data);
			return r ;
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
	
	@RequestMapping("VOCsCompany/GetZLDeviceData")
	public @ResponseBody Object GetZLDeviceData(HttpServletRequest request, HttpServletResponse response,
			long ID){
		try {
			QueryCompanyZlDevice queryCompanyZlDevice = new QueryCompanyZlDevice();
			queryCompanyZlDevice.setCOMPANYID(ID);
			List< CompanyZlDeviceDO > data = companyZlDeviceDAO.selectCompanyZlDeviceList(queryCompanyZlDevice);
			Map r = new HashMap();
			r.put("total", data.size());
			r.put("rows", data);
			return r ;
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
	
	@RequestMapping("VOCsCompany/GetJKDeviceInfoByID")
	public @ResponseBody Object GetJKDeviceInfoByID(HttpServletRequest request, HttpServletResponse response,
			long rowID ){
		try {
			List data = new ArrayList();
			data.add(companyJkDeviceDAO.selectCompanyJkDeviceById(rowID));
			return new DMResult(data,"查询成功",true);
		}catch (Exception e) {
				e.printStackTrace();
				return new DMResult("操作失败",false);
			}
	}
	
	@RequestMapping("VOCsCompany/GetZLDeviceInfoByID")
	public @ResponseBody Object GetZLDeviceInfoByID(HttpServletRequest request, HttpServletResponse response,
			long rowID ){
		try {
			List data = new ArrayList();
			data.add(companyZlDeviceDAO.selectCompanyZlDeviceById(rowID));
			return new DMResult(data,"查询成功",true);
		}catch (Exception e) {
				e.printStackTrace();
				return new DMResult("操作失败",false);
			}
	}
	
	@RequestMapping("VOCsCompany/saveJKDeviceData")
	public @ResponseBody Object saveJKDeviceData(HttpServletRequest request, HttpServletResponse response,
			CompanyJkDeviceDO CompanyJkDeviceDO){
		try {
			if(CompanyJkDeviceDO.getID() == null){
				companyJkDeviceDAO.insertCompanyJkDevice(CompanyJkDeviceDO);
			}else{
				companyJkDeviceDAO.updateCompanyJkDeviceById(CompanyJkDeviceDO);
			}
			return new DMResult("插入成功",true);
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
	
	@RequestMapping("VOCsCompany/saveZLDeviceData")
	public @ResponseBody Object saveZLDeviceData(HttpServletRequest request, HttpServletResponse response,
			CompanyZlDeviceDO CompanyZlDeviceDO){
		try {
			companyZlDeviceDAO.insertCompanyZlDevice(CompanyZlDeviceDO);
			return new DMResult("插入成功",true);
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
	
	@RequestMapping("VOCsCompany/DelJKDeviceInfoByID")
	public @ResponseBody Object DelJKDeviceInfoByID(HttpServletRequest request, HttpServletResponse response,
			long id){
		try {
			companyJkDeviceDAO.deleteById(id);
			return new DMResult("删除成功",true);
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
	
	@RequestMapping("VOCsCompany/DelZLDeviceInfoByID")
	public @ResponseBody Object DelZLDeviceInfoByID(HttpServletRequest request, HttpServletResponse response,
			long id){
		try {
			companyZlDeviceDAO.deleteById(id);
			return new DMResult("删除成功",true);
		}catch (Exception e) {
			e.printStackTrace();
			return new DMResult("操作失败",false);
		}
	}
}
